<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:fn="http://www.w3.org/2005/xpath-functions">
	
	<xsl:output method="text"
				encoding="utf-8"
				omit-xml-declaration="yes"
				indent="no"
				media-type="text/javascript"/>

	<xsl:template name="registerPackage">registerPackage({'full':"<xsl:value-of select="name(.)" />", 'suffix':":<xsl:value-of select="local-name(.)" />"}, "<xsl:value-of select="namespace-uri(.)" />");</xsl:template>

	<xsl:template match="/*">
		<xsl:call-template name="registerPackage"/>
		registerImport("<xsl:value-of select="name(.)"/>");
		<xsl:apply-templates select="child::node()" />
	</xsl:template>
	
	<xsl:template match="*">
		<xsl:choose>
			<xsl:when test="name(.)='fx:import'"><xsl:call-template name="import"/></xsl:when>
			<xsl:when test="name(.)='fx:html'"></xsl:when>
			<xsl:when test="name(.)='fx:script'"></xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="registerPackage"/>
				registerImport("<xsl:value-of select="name(.)"/>");
				<xsl:apply-templates select="child::node()" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template name="import">
		registerImport("<xsl:value-of select="@source"/>");
	</xsl:template>

</xsl:stylesheet>